{extend name="../../admin/view/common/main"/}

{block name="body"}
<div class="builder">
    <!-- 标题 -->
    <div class="main-title">
        <h2>
            {$title|htmlspecialchars}{if condition="$suggest"}<small>（{$suggest|htmlspecialchars}）</small>{/if}
        </h2>
    </div>

    <div class="with-padding">
        <!-- 表格列表-->
        <div class="tb-unit posr">
            <div class="tb-unit-bar">
                {volist name="buttonList" id="button"}
                    <{$button.tag} {$button.attr} style="margin-right:5px;">{$button.title|htmlspecialchars}</{$button.tag}>
                {/volist}
            </div>
            <div class="category">
                <div class="hd clearfix">
                    <div class="fold">折叠</div>
                    <div class="order">排序</div>
                    {volist name="keyList" id="field"}
                        <th>{$field.title|htmlspecialchars}</th>
                    {/volist}
                    <div class="name">名称</div>
                </div>
                {php}
                    $tree_list = new app\admin\builder\AdminTreeListBuilder();
                    $tree_list->setLevel($level);
                    $tree_list->setModel($model);
                    $tree_list->tree($tree);
                {/php}
            </div>
        </div>
        <!-- /表格列表-->
        <!-- 分页 -->
        <div class="page">
            {$page}
        </div>
    </div>
</div>
{/block}
{block name="script"}
    <script type="text/javascript">
        (function($){
            /* 分类展开收起 */
            $(".category dd").prev().find(".fold i").addClass("icon-unfold").click(function(){
                var self = $(this);
                if(self.hasClass("icon-unfold")){
                    self.closest("dt").next().slideUp("fast", function(){
                        self.removeClass("icon-unfold").addClass("icon-fold");
                    });
                } else {
                    self.closest("dt").next().slideDown("fast", function(){
                        self.removeClass("icon-fold").addClass("icon-unfold");
                    });
                }
            });

            /* 三级分类删除新增按钮 */
            $(".category dd dd .add-sub").remove();

            /* 实时更新分类信息 */
            $(".category")
            .on("submit", "form", function(){
                var self = $(this);
                $.post(self.attr("action"),self.serialize(),function(data){
                    /* 提示信息 */  
                    if(data.code){
                        toast.success(data.msg,'success');
                    } else {
                        toast.error(data.msg,'error');
                    }
                },"json");
                return false;
            })
            .on("focus","input",function(){
                $(this).data('param',$(this).closest("form").serialize());

            })
            .on("blur", "input", function(){
                if($(this).data('param')!=$(this).closest("form").serialize()){
                    $(this).closest("form").submit();
                }
            });
        })(jQuery);
    </script>
{/block}
